package com.qs.springboot.amqp.simple;

import com.qs.springboot.util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Send {

    private final static String QUEUE_NAME = "simple_queue";

    public static void main(String[] args) throws IOException, TimeoutException {
        //获取到连接及mq通道
        Connection connection = ConnectionUtil.getConnection();

        //从连接中获取到channel对象，提供channel完成api的大多数操作
        Channel channel = connection.createChannel();

        channel.queueDeclare(QUEUE_NAME, false, false, false, null);

        String message = "Hello World!";

        channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
        System.out.println("-->>发送消息：" + message);

        channel.close();
        connection.close();
    }
}
